
/**
 * Copyright (c) subnew ;
 * email:joseanluo@gmail.com;
 * Licensed under the GPL;  
 * @Title: RequirejsTag.java;
 * @Package com.subnew.framework.tag.common;
 */
package com.subnew.mango.frame.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import com.subnew.mango.frame.constant.RequirejsType;

/**
 * JS依赖加载TAG
 * @author JoseanLuo
 * @date  2014-7-21 上午12:56:15
 * @history new 
 * @version V1.0 
 */
public class RequirejsTag extends TagSupport{
	private static final long serialVersionUID = 2649345485443059512L;
	/**
	 * 需要加载的JS文件<br>
	 * 可加载JS目录，参考{@link RequirejsType}。自己也可以进行扩展。<br>
	 *多个JS文件以逗号分隔 
	 */
	String  require="default";
	
	public void setRequire(String require) {
		this.require = require;
	}
	
	public int doStartTag() throws JspException {
		return EVAL_PAGE;
	}

	public int doEndTag() throws JspException {
		try {
		JspWriter out = this.pageContext.getOut();
		StringBuffer sb = new StringBuffer();
		String [] requires=require.split(",");
		for(String jsname:requires){
			 sb.append(RequirejsType.valueOf(jsname).getUrl());
		}
		out.write(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}
}
